<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理
            <small>预约列表</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="search()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>

            <el-table size="small" current-row-key="id" :data="dataList" @selection-change="handleSelectionChange"
                      stripe highlight-current-row>
                <el-table-column type="selection" width="55" :reserve-selection='true'></el-table-column>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="idCard" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号码" align="center" sortable></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center" sortable></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">确认预约</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">取消预约</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div style="margin-top: 20px">
                <el-button type="primary" size="mini" @click="toggleSelection()" clearSelection>确认选中的预约</el-button>
                <el-button size="mini" type="danger" @click="toggleSelection2()">取消选中的预约</el-button>
            </div>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增" :visible.sync="dialogFormVisible" width="85%">
                    <el-container>
                        <el-aside width="350px">
                            <el-tabs v-model="activeName" type="card">
                                <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="身份证" prop="idCard">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="出生日期" prop="regTime">
                                                <el-col :span="22">
                                                    <el-date-picker type="date" placeholder="选择日期"
                                                                    v-model="formData.regTime"
                                                                    style="width: 100%;"></el-date-picker>
                                                </el-col>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="手机号" prop="phoneNumber">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="性别" prop="sex">
                                                <el-radio-group v-model="formData.sex" size="medium">
                                                    <el-radio border label="男"></el-radio>
                                                    <el-radio border label="女"></el-radio>
                                                </el-radio-group>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="年龄">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="22">
                                            <el-form-item label="预约时间" prop="orderDate">
                                                <el-col :span="22">
                                                    <el-date-picker type="date" placeholder="选择日期"
                                                                    v-model="formData.orderDate"
                                                                    style="width: 100%;"></el-date-picker>
                                                </el-col>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-form-item>
                                        <el-button type="primary" @click="submitForm()">立即创建</el-button>
                                        <el-button @click="dialogFormVisible = false;cancel()">取消</el-button>
                                    </el-form-item>
                                </el-form>
                            </el-tabs>

                        </el-aside>
                        <el-main>
                            <div class="filter-container2">
                                <el-input placeholder="检测套餐" v-model="pagination2.queryString" style="width: 200px;"
                                          class="filter-item"></el-input>
                                <el-button @click="search2()" class="dalfBut">查询</el-button>

                                <el-table size="small" current-row-key="id" :data="dataList2"
                                          @selection-change="handleSelectionChange2" stripe highlight-current-row>
                                    <el-table-column type="selection" width="50"
                                                     :reserve-selection='true'></el-table-column>
                                    <el-table-column prop="name" label="套餐名称" align="center"></el-table-column>
                                    <el-table-column prop="sex" label="适用人群" align="center"></el-table-column>
                                    <el-table-column prop="remark" label="套餐介绍" align="center"></el-table-column>
                                    <!--<el-table-column label="id" align="center">
                                        <template slot-scope="scope">
                                            <el-button type="primary" size="mini" @click="submitForm(scope.row2)"></el-button>
                                        </template>
                                    </el-table-column>-->
                                </el-table>
                                <div class="pagination2-container">
                                    <el-pagination
                                            class="pagiantion2"
                                            @current-change="handleCurrentChange2"
                                            :current-page="pagination2.currentPage"
                                            :page-size="pagination2.pageSize"
                                            layout="total, prev, pager, next, jumper"
                                            :total="pagination2.total">
                                    </el-pagination>
                                </div>
                            </div>
                        </el-main>
                    </el-container>
                    <!--<div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">保存</el-button>
                    </div>-->
                    <!--<div slot-scope="scope">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd(scope.row2)">保存</el-button>
                    </div>-->
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null,//查询条件
            },
            pagination2: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 3,//每页显示的记录数
                total: 0,//总记录数
                queryString: null,//查询条件

            },
            dataList: [
                /*orderDate: '2016-05-03',
                fileNumber:123,
                name: '王小虎',
                phoneNumber: '15071665617',
                orderType:'微信预约',
                orderStatus:'预约状态'*/
            ],//当前页要展示的分页列表数据
            dataList2: [],

            multipleSelection: [],
            formData: {
                /*name: '',
                idCard: '',
                regTime: '',
                phoneNumber: '',
                sex: '',
                age: '',
                orderDate: ''*/
            },//表单数据
            orderAndMemberIds: [],//预约列表分页查询数据id集合
            setmealIds: [],//预约列表新增弹窗分页查询数据id
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            rules: {//校验规则
                name: [{required: true, message: '请输入姓名', trigger: 'blur'},
                    {min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur'}],
                idCard: [{required: true, message: '请输入身份证号', trigger: 'blur'},
                    {min: 15, max: 18, message: '请输入正确的身份证号', trigger: 'blur'}],
                phoneNumber: [{required: true, message: '请输入手机号', trigger: 'blur'},
                    {min: 11, max: 11, message: '请输入正确的手机号', trigger: 'blur'}],
                orderDate: [{required: true, message: '请选择预约日期', trigger: 'change'}],
                regTime: [{required: true, message: '请选择出生日期', trigger: 'change'}],
                sex: [{required: true, message: '请选择性别', trigger: 'change'}]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();//VUE对象初始化完成后调用分页查询方法,完成分页查询
            //this.findPage2();
        },
        methods: {
            //多项改状态
            toggleSelection() {
                alert(this.orderAndMemberIds);
                axios.post("/order/updateOrderStatusSelection.do?ids=" + this.orderAndMemberIds).then((res) => {
                    if (res.data.flag) {
                        //弹出成功对话框
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });

                    } else {
                        //执行失败
                        //接收后台定义的MessageConstant类里的对应方法
                        this.$message.error(res.data.message);
                    }
                    this.orderAndMemberIds = [];
                    window.location.href = "order.html";
                }).finally(() => {
                    //window.location.herf="order.html";
                    //无论成功失败都调用分页查询方法
                    this.findPage();
                    //隐藏窗口
                    this.dialogFormVisible4Edit = false;
                });
            },
            toggleSelection2() {
                alert(this.orderAndMemberIds);
                axios.post("/order/updateOrderStatusSelection2.do?ids=" + this.orderAndMemberIds).then((res) => {
                    if (res.data.flag) {
                        //弹出成功对话框
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });

                    } else {
                        //执行失败
                        //接收后台定义的MessageConstant类里的对应方法
                        this.$message.error(res.data.message);
                    }
                    this.orderAndMemberIds = [];
                    window.location.href = "order.html";
                }).finally(() => {
                    //无论成功失败都调用分页查询方法
                    this.findPage();
                    //隐藏窗口
                    this.dialogFormVisible4Edit = false;
                });
            },
            handleSelectionChange(val) {
                var checkVal = new Array();
                for (i = 0; i < val.length; i++) {
                    checkVal.push(val[i].id);//选中项组成的数组
                }
                this.orderAndMemberIds = checkVal;
            },
            handleSelectionChange2(val) {
                this.multipleSelection = val;
                var checkVal = new Array();
                for (i = 0; i < val.length; i++) {
                    checkVal.push(val[i].id);//选中项组成的数组
                }
                this.setmealIds = checkVal;
            },
            //确定预约
            handleUpdate(row) {
                alert('你确定要预约嘛？');
                axios.post("/order/updateOrderStatus.do?id=" + row.id).then((res) => {
                    if (res.data.flag) {
                        //弹出成功对话框
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });
                    } else {
                        //执行失败
                        //接收后台定义的MessageConstant类里的对应方法
                        this.$message.error(res.data.message);
                    }
                    this.findPage();
                }).finally(() => {
                    window.location.herf = "order.html";
                    this.$refs.multipleTable.clearSelection();
                    //无论成功失败都调用分页查询方法
                    this.findPage();
                    //隐藏窗口
                    this.dialogFormVisible4Edit = false;
                });
            },
            //取消预约
            handleDelete(row) {
                alert('你确定要取消预约嘛？');
                axios.post("/order/updateOrderStatus2.do?id=" + row.id).then((res) => {
                    if (res.data.flag) {
                        //弹出成功对话框
                        this.$message({
                            type: 'success',
                            message: res.data.message
                        });
                        var phoneNumber = this.formData.phoneNumber;
                        axios.post("/order/send4Order.do?phoneNumber=" + phoneNumber)
                    } else {
                        //执行失败
                        //接收后台定义的MessageConstant类里的对应方法
                        this.$message.error(res.data.message);
                    }
                    this.findPage();
                }).finally(() => {
                    window.location.herf = "order.html";
                    this.$refs.multipleTable.clearSelection();
                    //无论成功失败都调用分页查询方法
                    this.findPage();
                    //隐藏窗口
                    this.dialogFormVisible4Edit = false;
                });
            },
            //新增
            submitForm() {
                //表单校验
                this.$refs['dataEditForm'].validate((valid) => {
                    if (valid) {
                        //表单校验通过,发送ajax请求,将录入的数据提交到后台进行处理
                        console.log(this.formData);
                        alert(this.setmealIds);
                        //this.formData.setmealId = this.orderAndMemberIds;
                        axios.post("/order/add.do?setmealIds=" + this.setmealIds, this.formData).then((res) => {
                            //关闭新增窗口
                            this.dialogFormVisible = false;
                            if (res.data.flag) {//只获取data数据
                                //执行成功
                                //新增成功后,重新调用分页查询方法,查询出最新的数据
                                this.findPage();
                                //弹出提示信息
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                            } else {
                                //执行失败
                                this.$message.error(res.data.message);
                            }
                        });
                        window.location.href = "order.html";
                    } else {
                        //表单校验不通过
                        this.$message.error("表单数据校验失败!");
                        return false;
                    }
                });
            },
            //重置表单
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            cancel() {
                window.location.href = "order.html";
            },
            //分页查询
            findPage() {
                //发送ajax请求，提交分页相关请求参数（页码、每页显示记录数、查询条件）
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/order/findPage.do", param).then((res) => {
                    //解析Controller响应回的数据，为模型数据赋值
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                });
            },
            findPage2() {
                //发送ajax请求，提交分页相关请求参数（页码、每页显示记录数、查询条件）
                var param = {
                    currentPage: this.pagination2.currentPage,
                    pageSize: this.pagination2.pageSize,
                    queryString: this.pagination2.queryString
                };
                axios.post("/setmeal/findPage2.do", param).then((res) => {
                    //解析Controller响应回的数据，为模型数据赋值
                    this.pagination2.total = res.data.total;
                    this.dataList2 = res.data.rows;
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};//重置数据
                this.handleCurrentChange2();
                this.search2();
            },
            // 弹出添加窗口
            handleCreate() {
                //弹出新增窗口
                this.dialogFormVisible = true;
                this.resetForm();//调用重置表单方法
            },
            //切换页码
            handleCurrentChange(currentPage) {
                //设置最新的页码
                this.pagination.currentPage = currentPage;
                //重新调用findPage方法进行查询
                this.findPage();
            }, handleCurrentChange2(currentPage) {
                //设置最新的页码
                this.pagination2.currentPage = currentPage;
                //重新调用findPage方法进行查询
                this.findPage2();
            },
            //搜索时把当前页改为1
            search() {
                this.pagination.currentPage = 1;
                this.findPage();
            }, search2() {
                this.pagination2.currentPage = 1;
                this.findPage2();
            },
            showMessage(r) {
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足
                    this.$message.error('无访问权限');
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            }
        }
    })
</script>
</html>